﻿(function () {
    var _inited = false;
    var tab = null;
    var accordion = null;
    var currentTab = "home";
    var tabIcon = 'Styles/images/icon.gif';
    //tabid计数器，保证tabid不会重复
    var tabidcounter = 0;
    var ProjectDialogInfo = {};
    var NewProjectDialogInfo = {};
    var ModuleDialogInfo = {};
    var SubModuleDialogInfo = {};
    var SubFieldDialogInfo = {};
    var NewSubFieldDialogInfo = {};
    var CompanyInfoDialogInfo = {};
    var ModuleInfoAddDialogInfo = {};
    var UploadControlDialogInfo = {};
    var DocumentOcrDialogInfo = {};
    var DocumentInfoDialogInfo = {};
    var PasswordInfoDialogInfo = {};
    var ModuleImportDialogInfo = {};

    var _DocumentHandler = "Handlers/DocumentInfoHandler.ashx";
    var _UserHandler = "Handlers/UserInfoHandler.ashx";

    function getStaticInfo() {
        $.ajax({
            type: "get",
            url: _UserHandler + "?action=GetUserGroup" + "&ts=" + new Date().valueOf(),
            dataType: 'json',
            success: function (data, textStatus) {
            }
        });
    }

    function ShowWaitWindow() {
        $.blockUI(
                    {
                        message: "执行中，请稍候...",
                        css:
                        { border: 'none',
                            padding: '10px',
                            backgroundColor: '#d6d6d6',
                            '-webkit-border-radius': '10px', '-moz-border-radius': '10px',
                            //opacity: .9,
                            color: 'Blue',
                            'font-size': '15px'

                        },
                        baseZ: 200000
                    }
                    );
    }
    function HideWaitWindow() {
        $.unblockUI();
    }


    //浏览器窗口高度变化 内容Tab reset事件
    function f_heightChanged(options) {
        if (tab)
            tab.addHeight(options.diff);
        if (accordion && options.middleHeight - 24 > 0)
            accordion.setHeight(options.middleHeight - 24);
    }

    //内容Tab 添加Tab事件
    function f_addTab(tabid, text, url) {
        tab.addTabItem({ tabid: tabid, text: text, url: url });
    }

    function f_resetTab(tabid) {
        tab.selectTabItem(tabid);
    }

    //初始化右边菜单栏
    function menuInit() {
        var menus = [];
        var mdocument = { MenuName: '文档管理', children: [{ MenuIcon: tabIcon, MenuName: '文档管理', MenuUrl: "Modules/DocumentInfoMgr.aspx", MenuNo: 'home'}], isShow: true };
        var mfunction = { MenuName: '功能模块', children: [], isShow: false };
        var msystem = { MenuName: '系统管理', children: [], isShow: false };
        var mfunctionid = null;
        var mfunctionitem = [];
        var param = top.IndexScript.getSystemParameter('UserMenuInfo');
        if (param && param != null) {
            for (var i = 0; i < param.length; i++) {
                switch (param[i].MenuName) {
                    /*case '文档管理':
                    {
                    var m = {};
                    m.MenuIcon = tabIcon;
                    m.MenuName = param[i].MenuName;
                    m.MenuUrl = "Modules/DocumentInfoMgr.aspx";
                    mdocument.children.push(m);
                    mdocument.isShow = true;
                    }
                    break;*/ 
                    case '功能模块':
                        {
                            mfunctionid = param[i].MenuId;
                        }
                        break;
                    case '模块设置':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = param[i].MenuName;
                            m.MenuUrl = "Modules/ModuleInfoMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '用户':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = '用户管理';
                            m.MenuUrl = "Modules/UserInfoMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '权限':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = '权限管理';
                            m.MenuUrl = "Modules/UserRightsMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '日志':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = '日志管理';
                            m.MenuUrl = "Modules/UserOperateLogMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '厂商信息':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = param[i].MenuName;
                            m.MenuUrl = "Modules/CompanyInfoMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '所属专业':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = param[i].MenuName;
                            m.MenuUrl = "Modules/ProfessionalInfoMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '文件类型':
                        {
                            var m = {};
                            m.MenuIcon = tabIcon;
                            m.MenuName = param[i].MenuName;
                            m.MenuUrl = "Modules/FileTypeInfoMgr.aspx";
                            msystem.children.push(m);
                            msystem.isShow = true;
                        }
                        break;
                    case '项目管理':
                        {
                            //$('li.projectmgr').show();
                        }
                        break;
                    default:
                        mfunctionitem.push(param[i]);
                        break;
                }
            }

            menus.push(mdocument);
            if (mfunctionitem && mfunctionitem != null/*&& mfunctionid != null*/) {
                for (var j = 0; j < mfunctionitem.length; j++) {
                    /*if (mfunctionitem[j].PrevMenuId == mfunctionid)*/
                    {
                        var msubfunction = { MenuName: mfunctionitem[j].MenuName, children: [], isShow: false };
                        var subinfo = mfunctionitem[j].MenuSubInfo;
                        if (subinfo && subinfo != null) {
                            for (var k = 0; k < subinfo.length; k++) {
                                var m = {};
                                m.MenuIcon = tabIcon;
                                m.MenuName = subinfo[k].ModuleSubName;
                                m.MenuUrl = "Modules/ModuleInfoShowMgr.aspx";
                                m.MenuUrl += "?ModuleSubID=" + subinfo[k].AutoID;
                                m.MenuUrl += "&MenuName=" + encodeURI(m.MenuName);
                                msubfunction.children.push(m);
                                msubfunction.isShow = true;
                            }
                        }
                        menus.push(msubfunction);
                    }
                }
            }
            //menus.push(mfunction);
            menus.push(msystem);
        }

        var MenuNo = 0;
        $(menus).each(function (i, menu) {
            if (menu.isShow) {
                var item = $('<div title="' + menu.MenuName + '"><ul class="menulist"></ul></div>');
                $(menu.children).each(function (j, submenu) {
                    var subitem = $('<li><img/><span></span><div class="menuitem-l"></div><div class="menuitem-r"></div></li>');
                    subitem.attr({
                        url: submenu.MenuUrl,
                        menuno: submenu.MenuNo ? submenu.MenuNo : ++MenuNo
                    });
                    $("img", subitem).attr("src", submenu.MenuIcon || submenu.icon);
                    $("span", subitem).html(submenu.MenuName || submenu.text);

                    if (submenu.SubMenu) {
                        subitem.addClass('submenu');
                    }

                    $("ul:first", item).append(subitem);
                });
                $("#accordion1").append(item);
            }
        });
        $("ul.menulist li").live('click', function () {
            var jitem = $(this);
            var tabid = jitem.attr("menuno");
            var url = jitem.attr("url");
            if (!url) return;
            //$(".l-tab-links .l-selected").removeClass("l-selected");
            //$("[tabid='home']").addClass("l-selected");
            if (tab.isTabItemExist(tabid)) {
                f_resetTab(tabid);
            }
            else {
                f_addTab(tabid, jitem.find('>span').html(), url);
            }

            /*if ($("#home").attr("src") != url) {
            $("#home").attr("src", url);
            $(".l-selected a").html($("span:first", jitem).html());
            }*/
            var contentitem = $(".l-tab-content-item[tabid=" + tabid + "]");
            var iframeloading = $(".l-tab-loading:first", contentitem);
            var iframe = $("iframe:first", contentitem);
            var url = $(iframe).attr("src");
            iframeloading.show();
            iframe.attr("src", url).unbind('load.tab').bind('load.tab', function () {
                iframeloading.hide();
            });
        }).live('mouseover', function () {
            var jitem = $(this);
            jitem.addClass("over");
        }).live('mouseout', function () {
            var jitem = $(this);
            jitem.removeClass("over");
        });
        pageInit();

    }

    //初始化页面控件事件
    function pageInit() {
        //平台布局
        $("#layout1").ligerLayout({ minLeftWidth: 0, leftWidth: 190, height: '100%', heightDiff: -34, space: 4, onHeightChanged: f_heightChanged });
        var height = $(".l-layout-center").height();
        //内容Tab
        $("#framecenter").ligerTab({ height: height });
        //菜单面板
        $("#accordion1").ligerAccordion({ height: height - 24 });
        tab = $("#framecenter").ligerGetTabManager();
        accordion = $("#accordion1").ligerGetAccordionManager();
        $("#pageloading").hide();
        setInterval('$("#spnDate").html($.DateFromObj2String((new Date()).valueOf()))', 1000);
    }

    function InitProjectDialog() {
        $('li.projectmgr a').bind('click', function () {
            IndexScript.ProjectDialog.Open(ProjectInfoMgr.getProjectInfo(), null);
            /*var info = {};
            info.CompanyName = '江苏舜天';
            top.IndexScript.CompanyInfoDialog.Open(info, null);*/
            return false;
        });
        $('#ProjectDialog').dialog({
            autoOpen: false,
            title: "项目管理",
            width: 400,
            height: 300,
            modal: true,
            beforeclose: function (e, ui) {
                var pi = ProjectInfoMgr.getSelectProject();
                if (pi == null) {
                    alert('请选择项目');
                    return false;
                }
                return true;
            }
        });
    }

    function InitNewProjectDialog() {
        $('#NewProjectDialog').dialog({
            autoOpen: false,
            title: "项目编辑",
            width: 400,
            height: 180,
            modal: true
        });

        $('#btnNewProjectConfirm', '#NewProjectDialog').bind('click', function () {
            if ($.trim($('#txtProjectName', '#NewProjectDialog').val()) == '') {
                alert('请输入项目名称');
                return false;
            }
            if ($.trim($('#txtProjectDisk', '#NewProjectDialog').val()) == '') {
                alert('请输入项目磁盘');
                return false;
            }
            if (NewProjectDialogInfo && NewProjectDialogInfo.cb) {
                var info = NewProjectDialogInfo.info;
                if (info == null) {
                    info = {};
                }
                info.ProjectName = $.trim($('#txtProjectName', '#NewProjectDialog').val());
                info.Description = $.trim($('#txtProjectDescription', '#NewProjectDialog').val());
                info.ProjectDisk = $.trim($('#txtProjectDisk', '#NewProjectDialog').val());
                NewProjectDialogInfo.cb(info);
            }
            top.IndexScript.NewProjectDialog.Close();
        });
        $('#btnNewProjectCancel', '#NewProjectDialog').bind('click', function () {
            top.IndexScript.NewProjectDialog.Close();
        });
    }

    function InitModuleDialog() {
        $('#ModuleDialog').dialog({
            autoOpen: false,
            title: "主功能模块编辑",
            width: 400,
            height: 160,
            modal: true
        });
        $('#btnModuleConfirm', '#ModuleDialog').bind('click', function () {
            if ($.trim($('#txtModuleName', '#ModuleDialog').val()) == '') {
                alert('请输入主模块名称');
                return false;
            }
            if (ModuleDialogInfo && ModuleDialogInfo.cb) {
                var info = ModuleDialogInfo.info;
                if (info == null) {
                    info = {};
                }
                info.ModuleName = $.trim($('#txtModuleName', '#ModuleDialog').val());
                info.Description = $.trim($('#txtModuleDescription', '#ModuleDialog').val());
                ModuleDialogInfo.cb(info);
            }
            top.IndexScript.ModuleDialog.Close();
        });
        $('#btnModuleCancel', '#ModuleDialog').bind('click', function () {
            top.IndexScript.ModuleDialog.Close();
        });
    }

    function InitSubModuleDialog() {
        $('#SubModuleDialog').dialog({
            autoOpen: false,
            title: "子功能模块编辑",
            width: 400,
            height: 160,
            modal: true
        });
        $('#btnSubModuleConfirm', '#SubModuleDialog').bind('click', function () {
            if ($.trim($('#txtSubModuleName', '#SubModuleDialog').val()) == '') {
                alert('请输入子模块名称');
                return false;
            }
            if (SubModuleDialogInfo && SubModuleDialogInfo.cb) {
                var info = SubModuleDialogInfo.info;
                if (info == null) {
                    info = {};
                }
                info.ModuleSubName = $.trim($('#txtSubModuleName', '#SubModuleDialog').val());
                info.Description = $.trim($('#txtSubModuleDescription', '#SubModuleDialog').val());
                SubModuleDialogInfo.cb(info);
            }
            top.IndexScript.SubModuleDialog.Close();
        });
        $('#btnSubModuleCancel', '#SubModuleDialog').bind('click', function () {
            top.IndexScript.SubModuleDialog.Close();
        });
    }

    function InitSubFieldDialog() {
        $('#SubFieldDialog').dialog({
            autoOpen: false,
            title: "子功能模块设置",
            width: 700,
            height: 300,
            modal: true
        });
    }

    function InitNewSubFieldDialog() {
        $('#NewSubFieldDialog').dialog({
            autoOpen: false,
            title: "子功能字段编辑",
            width: 400,
            height: 320,
            modal: true
        });

        $('#sltFieldType', '#NewSubFieldDialog').bind('change', function () {
            var filedLen = $.trim($('#txtFieldLen', '#NewSubFieldDialog').val());
            switch ($(this).val()) {
                case 'C':
                    {
                        /*if (filedLen == '')*/
                        {
                            $('#txtFieldLen', '#NewSubFieldDialog').val('50');
                        }
                        $('#txtFieldLen', '#NewSubFieldDialog').removeAttr('disabled');
                        $('#txtIniValue', '#NewSubFieldDialog').removeAttr('disabled');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').removeAttr('disabled');
                    }
                    break;
                case 'I':
                    {
                        /*if (filedLen == '')*/
                        {
                            $('#txtFieldLen', '#NewSubFieldDialog').val('1');
                        }
                        $('#txtFieldLen', '#NewSubFieldDialog').removeAttr('disabled');
                        $('#txtIniValue', '#NewSubFieldDialog').attr('disabled', 'disabled');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').val('0');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').attr('disabled', 'disabled');
                    }
                    break;
                case 'D':
                    {
                        $('#txtFieldLen', '#NewSubFieldDialog').val('1');
                        $('#txtFieldLen', '#NewSubFieldDialog').attr('disabled', 'disabled');
                        $('#txtIniValue', '#NewSubFieldDialog').attr('disabled', 'disabled');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').val('0');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').attr('disabled', 'disabled');
                    }
                    break;
                case 'B':
                    {
                        $('#txtFieldLen', '#NewSubFieldDialog').val('1');
                        $('#txtFieldLen', '#NewSubFieldDialog').attr('disabled', 'disabled');
                        $('#txtIniValue', '#NewSubFieldDialog').attr('disabled', 'disabled');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').val('0');
                        $('#sltSpecialFlag', '#NewSubFieldDialog').attr('disabled', 'disabled');
                    }
                    break;
            }
        });

        $('#btnNewSubFieldConfirm', '#NewSubFieldDialog').bind('click', function () {
            if ($.trim($('#txtFieldName', '#NewSubFieldDialog').val()) == '') {
                alert('请输入字段名称');
                return false;
            }
            if ($.trim($('#txtFieldLen', '#NewSubFieldDialog').val()) == '') {
                alert('请输入字段长度');
                return false;
            }
            /*if ($.trim($('#txtIniValue', '#NewSubFieldDialog').val()) == '') {
            alert('请输入初始值');
            return false;
            }*/
            if (NewSubFieldDialogInfo && NewSubFieldDialogInfo.cb) {
                var info = NewSubFieldDialogInfo.info;
                if (info == null) {
                    info = {};
                }
                info.FieldName = $.trim($('#txtFieldName', '#NewSubFieldDialog').val());
                info.FieldType = $('#sltFieldType', '#NewSubFieldDialog').val();
                info.FieldLen = $.trim($('#txtFieldLen', '#NewSubFieldDialog').val());
                info.QueryFlag = $('#cbQueryFlag', '#NewSubFieldDialog').attr('checked') ? 1 : 2;
                info.ResultFlag = $('#cbResultFlag', '#NewSubFieldDialog').attr('checked') ? 1 : 2;
                info.SpecialFlag = $('#sltSpecialFlag', '#NewSubFieldDialog').val();
                info.IniValue = $.trim($('#txtIniValue', '#NewSubFieldDialog').val());
                info.BlankFlag = $('#cbBlankFlag', '#NewSubFieldDialog').attr('checked') ? 2 : 1;
                var result = NewSubFieldDialogInfo.cb(info);
                if (!result) {
                    return;
                }
            }
            top.IndexScript.NewSubFieldDialog.Close();
        });
        $('#btnNewSubFieldCancel', '#NewSubFieldDialog').bind('click', function () {
            top.IndexScript.NewSubFieldDialog.Close();
        });
    }

    function InitCompanyInfoDialog() {
        $('#CompanyInfoDialog').dialog({
            autoOpen: false,
            title: "厂商选择",
            width: 400,
            height: 300,
            modal: true
        });
        $('#btnCompanyInfoConfirm', '#CompanyInfoDialog').bind('click', function () {
            var info = CompanyDialogMgr.GetInfo();
            if (info == null) {
                alert('请选择厂商');
                return false;
            }
            if (CompanyInfoDialogInfo && CompanyInfoDialogInfo.cb) {
                CompanyInfoDialogInfo.cb(info);
            }
            top.IndexScript.CompanyInfoDialog.Close();
        });
        $('#btnCompanyInfoCancel', '#CompanyInfoDialog').bind('click', function () {
            top.IndexScript.CompanyInfoDialog.Close();
        });
    }

    function UploadFiles(data) {

        if ($('#fileInput').val() == "") {
            alert("请选择文件");
            return;
        }
        ShowWaitWindow()
        $.ajaxFileUpload({
            url: _DocumentHandler + "?action=UploadFiles",
            secureuri: false, //异步
            fileElementId: 'fileInput', //上传控件ID
            Params: encodeURIComponent($.toJSON(data)),
            dataType: 'json', //返回的数据信息格式          		
            success: function (data, Status) {
                if (data.result) {
                    HideWaitWindow();
                    UploadControlDialogInfo.cB();
                    $('#UploadFilesDialog').dialog("close");
                }
                else {
                    HideWaitWindow();
                    alert('上传失败，文件名已存在');
                }
            },
            error: function (err, Status) {
                alert(err);
            }
        });
    }


    function InitUploadFilesDialog() {
        $('#UploadFilesDialog').dialog({
            autoOpen: false,
            title: "上传文件",
            width: 400, modal: true,
            buttons: {
                "确定": function () {
                    var param = $('#UploadFilesDialog').data('data');
                    if (param == null || param == "") {
                        alert("上传路径丢失，本次上传操作将终止，请重新操作！");
                        $(this).dialog("close");
                        return;
                    }
                    /*if ($.trim($('#txtAttachmentsName').val()) == "") {
                    alert('请输入文件名称');
                    return;
                    }*/
                    var pPar = {
                        Name: $('#txtAttachmentsName').val(),
                        UploadPath: param
                    };
                    UploadFiles(pPar);
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
    }

    function InitCreateFolderDialog() {
        $("#CreateFolderDialog").dialog({
            autoOpen: false,
            title: "创建文件夹",
            width: 400, modal: true,
            buttons: {
                "确定": function () {
                    var param = $('#CreateFolderDialog').data('data');
                    if (param == null || param == "") {
                        alert("创建路径丢失，本次操作将终止，请重新操作！");
                        $(this).dialog("close");
                        return;
                    }
                    if ($.trim($('#txtFolderName').val()) == "") {
                        alert('请输入文件夹名称');
                        return;
                    }
                    $.ajaxQuest('get', _DocumentHandler + '?action=CreateFolder&Params=' + param + "\\" + $('#txtFolderName').val(), true, function (result) {
                        if (result) {
                            UploadControlDialogInfo.cB();
                            $("#CreateFolderDialog").dialog("close");
                        }
                        else
                            alert("系统错误，创建文件夹失败！");
                    });
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
    }

    function InitDocumentOcrDialog() {
        $("#DocumentOcrDialog").dialog({
            autoOpen: false,
            title: "OCR扫描设置",
            width: 300,
            modal: true
        });
        $('#btnDocumentOcrConfirm', '#DocumentOcrDialog').bind('click', function () {
            if (DocumentOcrDialogInfo && DocumentOcrDialogInfo.cb) {
                var info = DocumentOcrDialogInfo.info || {};
                info.Language = $('#sltLanguage', '#DocumentOcrDialog').val();
                info.DoBlackWhite = $('#cbDoBlackWhite', '#DocumentOcrDialog').attr('checked') ? 1 : 2;
                info.DoColorFilter = $('#cbDoColorFilter', '#DocumentOcrDialog').attr('checked') ? 1 : 2;
                info.DoNoiseReduce = $('#cbDoNoiseReduce', '#DocumentOcrDialog').attr('checked') ? 1 : 2;
                info.DoExpand = $('#cbDoExpand', '#DocumentOcrDialog').attr('checked') ? 1 : 2;
                info.Description = '';
                DocumentOcrDialogInfo.cb(info);
            }
            top.IndexScript.DocumentOcrDialog.Close();
        });
        $('#btnDocumentOcrCancel', '#DocumentOcrDialog').bind('click', function () {
            top.IndexScript.DocumentOcrDialog.Close();
        });
    }

    function InitPasswordInfoDialog() {
        function handlerMsg(msg) {
            switch (msg) {
                case 0:
                    alert('操作成功');
                    break;
                case 100:
                    alert('用户名相同');
                    break;
                case 200:
                    alert('旧口令不正确');
                    break;
                default:
                    alert('操作失败');
                    break;
            }
        }
        function modifyPassword(oldpsw, psw) {
            $.ajax({
                type: "post",
                url: _UserHandler,
                data: "action=ModifyPassword&OldPassword=" + encodeURIComponent(oldpsw) + "&Password=" + encodeURIComponent(psw),
                dataType: 'json',
                success: function (data, textStatus) {
                    ProcessAjaxResult(data, textStatus,
                    function (data, textStatus) {
                        handlerMsg(data);
                    },
                    function (err, textStatus) {
                        alert('操作失败');
                    },
                    this);
                }
            });
        }
        $('li.passwordmgr a').bind('click', function () {
            IndexScript.PasswordInfoDialog.Open(null, function (oldpsw, psw) {
                modifyPassword(oldpsw, psw);
            });
            return false;
        });
        $("#PasswordInfoDialog").dialog({
            autoOpen: false,
            title: "修改密码",
            width: 300,
            height: 170,
            modal: true
        });
        $('#btnPasswordConfirm', '#PasswordInfoDialog').bind('click', function () {
            if ($.trim($('#txtOldPassword', '#PasswordInfoDialog').val()) == '') {
                alert('请输入旧密码');
                return;
            }
            if ($.trim($('#txtPassword', '#PasswordInfoDialog').val()) == '') {
                alert('请输入新密码');
                return;
            }
            if ($.trim($('#txtPasswordConfirm', '#PasswordInfoDialog').val()) == '') {
                alert('请确认密码');
                return;
            }
            if ($.trim($('#txtPassword', '#PasswordInfoDialog').val()) != $.trim($('#txtPasswordConfirm', '#PasswordInfoDialog').val())) {
                alert('请输入一致的密码');
                return;
            }
            if (PasswordInfoDialogInfo && PasswordInfoDialogInfo.cb) {
                PasswordInfoDialogInfo.cb($.trim($('#txtOldPassword', '#PasswordInfoDialog').val()), $.trim($('#txtPassword', '#PasswordInfoDialog').val()));
            }
            top.IndexScript.PasswordInfoDialog.Close();
        });
        $('#btnPasswordCancel', '#PasswordInfoDialog').bind('click', function () {
            top.IndexScript.PasswordInfoDialog.Close();
        });
    }

    function InitModuleImportDialog() {
        $('#ModuleImportDialog').dialog({
            autoOpen: false,
            title: "复制",
            width: 400,
            height: 300,
            modal: true
        });
        $('#btnModuleImportConfirm', '#ModuleImportDialog').bind('click', function () {
            var pi = null;
            var cbproject = $('#tbprojectimport', '#ModuleImportDialog').find('.cbproject');
            if (cbproject && cbproject != null) {
                $(cbproject).each(function () {
                    if ($(this).attr('checked')) {
                        var tr = $(this).closest('tr');
                        pi = tr.data();
                        return false;
                    }
                });
            }

            if (pi == null) {
                alert('请选择项目');
                return;
            }

            if (ModuleImportDialogInfo && ModuleImportDialogInfo.cb) {
                ModuleImportDialogInfo.cb(pi);
            }
            top.IndexScript.ModuleImportDialog.Close();
        });
        $('#btnModuleImportCancel', '#ModuleImportDialog').bind('click', function () {
            top.IndexScript.ModuleImportDialog.Close();
        });

        //项目选择框同时只能选择一个
        $('.cbproject', '#tbprojectimport').die().live('click', function () {
            if ($(this).attr('checked')) {
                $('.cbproject', '#tbprojectimport').removeAttr('checked');
                $(this).attr('checked', 'checked');
            }
        });
    }

    function InitDocumentInfoDialog() {
        var _handler = "Handlers/DocumentInfoHandler.ashx";
        $("#DocumentInfoDialog").dialog({
            autoOpen: false,
            title: "文档选择",
            width: 700,
            height: 500,
            modal: true
        });

        $('#btnDocumentInfoClear', '#DocumentInfoDialog').bind('click', function () {
            $('#txtDocumentInfoPath').val('');
            $('#txtDocumentInfoPath').data('data', null);
        });
        $('#btnDocumentInfoConfirm', '#DocumentInfoDialog').bind('click', function () {
            if (DocumentInfoDialogInfo && DocumentInfoDialogInfo.cb) {
                var info = DocumentInfoDialogInfo.info || {};
                info.FilePath = $('#txtDocumentInfoPath').val();
                info.FileData = $('#txtDocumentInfoPath').data('data');
                DocumentInfoDialogInfo.cb(info);
            }
            top.IndexScript.DocumentInfoDialog.Close();
        });
        $('#btnDocumentInfoCancel', '#DocumentInfoDialog').bind('click', function () {
            top.IndexScript.DocumentInfoDialog.Close();
        });

        //init tree and panel
        SplitterContainer();

        //get folder tree
        GetFolderTree();

        //bind folder double click
        $("#ThumbnailList li[nt='1']").live("dblclick", function () {
            var curPath = $(this).attr('filepath');
            if (curPath == "" || curPath == null) {
                return;
            }
            $("#txtFilePath").val(curPath).attr('autoid', $(this).attr('autoid'));
            $('.filetree').find('span.folder').removeClass('selected');
            $('.filetree').find('ul[autoid=' + $(this).attr('autoid') + ']').prev('span').addClass('selected');
            GetFolderInfo($(this).attr('autoid'));
        });

        //bind li css
        $("#ThumbnailList li").live('click', function () {
            $("#ThumbnailList li").removeClass('onlight');
            $(this).addClass('onlight');
            if ($(this).attr('nt') != '1') {
                var fullpath = $(this).attr('filepath');
                var lidata = $(this).data('data');
                $('#txtDocumentInfoPath').val(fullpath).data('data', lidata);
            }
        });

        //bind table dblclick
        $("#TableList tr.ui-row-ltr").live("dblclick", function (e) {
            var target = $(e.target || e.srcElement);
            if (target.is("tr.ui-row-ltr *")) {
                target = target.parents("tr.ui-row-ltr");
            }
            if (target.is("tr.ui-row-ltr")) {
                var elem = target.find('div[nt]');
                if (elem.attr('nt') == 1) {
                    var curPath = elem.attr('filepath');
                    if (curPath == "" || curPath == null) {
                        return;
                    }
                    var autoid = elem.attr('autoid');
                    $("#txtFilePath").val(curPath).attr('autoid', autoid);
                    $('.filetree').find('span.folder').removeClass('selected');
                    $('.filetree').find('ul[autoid=' + autoid + ']').prev('span').addClass('selected');
                    GetFolderInfo(autoid);
                }
            }
        });

        //bind table click
        /*$("#TableList tr.ui-row-ltr").live("click", function (e) {
        var target = $(e.target || e.srcElement);
        if (target.is("tr.ui-row-ltr *")) {
        target = target.parents("tr.ui-row-ltr");
        }
        if (target.is("tr.ui-row-ltr")) {
        var elem = target.find('div[nt]');
        if (elem.attr('nt') != 1) {
        var fullpath = elem.attr('filepath');
        var lidata = elem.data('data');
        $('#txtDocumentInfoPath').val(fullpath).data('data', lidata);
        }
        }
        });*/

        $("#TableList").bind('click', function (e) {
            var target = $(e.target || e.srcElement);
            if (target.is("tr.ui-row-ltr *")) {
                target = target.parents("tr.ui-row-ltr");
            }
            if (target.is("tr.ui-row-ltr")) {
                var elem = target.find('div[nt]');
                if (elem.attr('nt') != 1) {
                    var fullpath = elem.attr('filepath');
                    var lidata = elem.data('data');
                    $('#txtDocumentInfoPath').val(fullpath).data('data', lidata);
                }
            }
        });

        //full text search
        $("#btnFullTextSearch").bind("click", function () {
            var curPath = $("#txtFilePath").val();
            if (curPath == "" || curPath == null) {
                alert("请选择一个文件夹作为检索路径！"); return;
            }
            if ($.trim($("#txtFullTextSearch").val()) == "") {
                alert("请输入关键字！"); return;
            }
            var autoid = $("#txtFilePath").attr('autoid');
            var SearchKey = $("#txtFullTextSearch").val();
            $("#lbPublicSearchResult").attr("prevPath", autoid);
            $("#lbPublicSearchResult").attr("prevKey", SearchKey);
            GetFolderInfo(autoid, SearchKey);
            $("#txtFilePath").val('');
            $("#txtFilePath").removeAttr('autoid');
            $('.filetree').find('span.folder').removeClass('selected');
            $('.filetree').find('span.searchresult').addClass('selected');
        });

        $("#TableList").jqGrid({
            datatype: "local",
            colNames: ['图标', '文件名', '扩展名', '扫描标记'],
            colModel: [
            { name: '图标', index: '图标', width: 100, sortable: true, align: 'center' },
            { name: '文件名', index: '文件名', width: 200, sortable: true },
            { name: '扩展名', index: '扩展名', width: 100, sortable: true },
            { name: '扫描标记', index: '扫描标记', width: 100, sortable: true },
            ],
            multiselect: false,
            shrinkToFit: false,
            forceFit: false,
            rowNum: 100000
        });

        //mode switch
        $('.btnIconmode').bind("click", function () {
            SwitchShowMode('Icon');
        });

        $('.btnDetailmode').bind("click", function () {
            SwitchShowMode('Details');
        });

        $('.btnSwithmode').bind('click', function () {
            SwitchShowMode();
        });

        $('.btnUplevel').bind('click', function () {
            UpLevel();
        });

        function GetParentNode(folderid) {
            var PrevFolderID = -1;
            if (_foldertree != null) {
                for (var j = 0; j < _foldertree.length; j++) {
                    if (_foldertree[j].DeleteFlag == 2) {
                        if (_foldertree[j].AutoID == folderid) {
                            PrevFolderID = _foldertree[j].PrevFolderID;
                            break;
                        }
                    }
                }
            }
            return PrevFolderID;
        }

        function UpLevel() {
            var curPath = $("#txtFilePath").val();
            if (curPath == "" || curPath == null) {
                alert("已经是最顶层！"); return;
            }
            var autoid = $("#txtFilePath").attr('autoid');
            var PrevFolderID = GetParentNode(autoid);
            if (PrevFolderID >= 0) {
                $('.filetree').find('span.folder').removeClass('selected');
                $('.filetree').find('ul[autoid=' + PrevFolderID + ']').prev('span').addClass('selected');

                var ilength = curPath.lastIndexOf("\\");
                var fullpath = curPath.substring(0, ilength);
                $("#txtFilePath").val(fullpath).attr('autoid', PrevFolderID);

                GetFolderInfo(PrevFolderID);
            }
        }

        function SwitchShowMode(params) {
            if (params == "Details") {
                $("#ThumbnailListContainer").hide();
                $("#TableListContainer").show();
            } else if (params == "Icon") {
                $("#ThumbnailListContainer").show();
                $("#TableListContainer").hide();
            }
            else {
                if (_mode == "Details") {
                    $("#ThumbnailListContainer").show();
                    $("#TableListContainer").hide();
                    params = "Icon";
                }
                else {
                    $("#ThumbnailListContainer").hide();
                    $("#TableListContainer").show();
                    params = "Details";
                }
            }
            _mode = params;
            SetGridRange();
        }

        SwitchShowMode('Icon');

        function ClearContent() {
            jQuery("#TableList").jqGrid('clearGridData', false);
            jQuery("#ThumbnailList li").remove();
        }

        function SetGridRange() {
            var x = $('#mlcontent').width();
            jQuery("#TableList").jqGrid('setGridWidth', x);
            var y = $('#mlcontent').height();
            jQuery("#TableList").jqGrid('setGridHeight', y - 40);
            $('#ThumbnailList').height(y + 'px');
        }

        function SplitterContainer() {
            $('#splitcontanainer').SplitterContainer({
                panel1: { obj: $('#mainTree'), cssClass: 'treepanel', minWidth: 0 },
                panel2: { obj: $('#ContentPanel'), cssClass: 'contentpanel', minWidth: 0 },
                panel1InitWidth: 245,
                splitterCssClass: 'splitter',
                enableSplitterDblClick: false,
                fixedPanel: 'p1',
                onsplitted: function () { SetGridRange(); }
            });
            $(window).resize(SetGridRange);
        }

        /*function SetGridRange() {
        var x = $('#mlcontent').width();
        var y = $('#mlcontent').height();
        $('#ThumbnailList').height(y + 'px');
        }*/

        function GetFolderTree() {
            $.ajax({
                type: "get",
                url: _handler,
                data: "action=GetFolderTree" + "&ts=" + new Date().valueOf(),
                dataType: 'json',
                success: function (data, textStatus) {
                    ProcessAjaxResult(data, textStatus,
                    function (data, textStatus) {
                        _foldertree = data;
                        //BuildFolderTree(data, 1);
                        InitTree();
                    },
                    function (err, textStatus) {
                        alert('操作失败');
                    },
                    this);
                }
            });
        }

        function BuildFolderTree(data, level, previd) {
            var leftData = [];
            if (data && data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].DeleteFlag == 2) {
                        if (data[i].FolderLevel == level && data[i].PrevFolderID == previd) {
                            var ul = $('ul[autoid="' + data[i].PrevFolderID + '"]');
                            var ulpath = ul.attr('fullpath');
                            if (level != 1) {
                                ulpath += "\\";
                            }
                            var li = '<li class="closed">';
                            li += '<span class="folder"><label>';
                            li += data[i].FolderName;
                            li += '</label></span>';
                            li += '<ul class="treeul" fullpath="' + ulpath + data[i].FolderName + '"';
                            li += 'autoid="' + data[i].AutoID + '" level="' + (parseInt(level) + 1) + '"></ul></li>';

                            var b = $(li).appendTo('ul[autoid="' + data[i].PrevFolderID + '"]').data("data", data[i]);
                            //$('ul[autoid="' + data[i].PrevFolderID + '"]').append($(li).data('data', data[i]));
                            $('.filetree').treeview({ add: b });
                        }
                        else {
                            leftData.push(data[i]);
                        }
                    }
                }
            }
        }

        function InitTree() {
            $('.filetree').treeview({
                collapsed: false,
                animated: "medium",
                persist: "location",
                toggle: function () {
                    var currentobj = $(this);
                    if (!currentobj.is(":hidden")) {
                        //不需要处理折叠事件
                        var ul = currentobj;
                        ul.empty();
                        BuildFolderTree(_foldertree, ul.attr('level'), ul.attr('autoid'));
                    }
                },
                nodeclick: function () {
                    //var currentPath = $($(this).next()).attr('fullpath');
                    var autoid = $(this).attr('autoid');
                    if (!autoid) {
                        if ($(this).hasClass('searchresult')) {
                            $('.filetree').find('span.folder').removeClass('selected');
                            $('.filetree').find('span.searchresult').addClass('selected');
                            //$("#ThumbnailList").html("");
                            ClearContent();
                            var prevPath = $("#lbPublicSearchResult").attr("prevPath");
                            var prevKey = $("#lbPublicSearchResult").attr("prevKey");
                            if (prevPath != null && prevPath != '') {
                                GetFolderInfo(prevPath, prevKey);
                            }
                            return;
                        }
                        else {
                            return;
                        }
                    }

                    $('.filetree').find('span.folder').removeClass('selected');
                    $('.filetree').find('ul[autoid=' + autoid + ']').prev('span').addClass('selected');

                    var fullpath = $(this).attr('fullpath');
                    $("#txtFilePath").val(fullpath).attr('autoid', autoid);
                    GetFolderInfo(autoid);
                }
            });
        }

        function GetFolderInfo(folderid, keywords) {
            $(window).trigger('resize');
            if (!keywords) {
                keywords = '';
            }
            top.IndexScript.WaitWindow.Show();
            $.ajax({
                type: "get",
                url: _handler,
                data: "action=GetFolderInfo&Params=" + folderid + "&KeyWord=" + encodeURIComponent(keywords) + "&ts=" + new Date().valueOf(),
                dataType: 'json',
                success: function (data, textStatus) {
                    ProcessAjaxResult(data, textStatus,
                    function (data, textStatus) {
                        //$("#ThumbnailList").html("");
                        ClearContent();
                        var icount = 0;
                        //bind folder
                        if (keywords == '' || keywords == null) {
                            var tmpval = $("#txtFilePath").val();
                            if (tmpval == undefined || tmpval == null || tmpval == "") {
                                tmpval = "";
                            }
                            else {
                                tmpval += "\\";
                            }
                            for (var j = 0; j < _foldertree.length; j++) {
                                if (_foldertree[j].DeleteFlag == 2) {
                                    if (_foldertree[j].PrevFolderID == folderid) {

                                        var fp = $('ul[autoid="' + _foldertree[j].AutoID + '"]').attr('fullpath');
                                        if (fp == undefined) {
                                            fp = tmpval + _foldertree[j].FolderName;
                                        }

                                        //bind icon
                                        var li = "<li nt='1' filePath='" + fp + "'";
                                        li += "autoid='" + _foldertree[j].AutoID + "'";
                                        li += "class='Thumbnail_item'><div class='stamp_warper stamp1'";
                                        li += "></div><div class='info_warper' title='";
                                        li += _foldertree[j].FolderName + "'><label class='title_warper'>" + _foldertree[j].FolderName + "</label></div></li>";
                                        $("#ThumbnailList").append(li);

                                        //bind details
                                        icount = j;
                                        var imgelem = "<div class='detail_warper detail1'";
                                        imgelem += " nt='1'";
                                        imgelem += " filePath='" + fp + "'";
                                        imgelem += " autoid='" + _foldertree[j].AutoID + "'></div>";
                                        $("#TableList").jqGrid('addRowData', icount + 1,
            		                    {
            		                        '图标': imgelem,
            		                        '文件名': _foldertree[j].FolderName,
            		                        '扩展名': "",
            		                        '扫描标记': ""
            		                    });
                                    }
                                }
                            }
                        }
                        //bind file
                        if (data != null && data.length > 0) {
                            var contentItemHtmlStr = "";
                            for (var i = 0; i < data.length; i++) {
                                if (data[i].DeleteFlag == 2) {
                                    var li = "<li filePath='" + data[i].FilePath + "' nt='" + GetDocumnetType(data[i].FileExt) + "' ";
                                    li += "autoid='" + data[i].AutoID + "'";
                                    li += "class='Thumbnail_item'><div class='stamp_warper stamp";
                                    li += GetDocumnetType(data[i].FileExt);
                                    if (data[i].OCRFlag == 1) {
                                        li += " ocrflag";
                                    }
                                    li += "' ocrflag='" + data[i].OCRFlag;
                                    li += "'></div><div class='info_warper' title='";
                                    li += data[i].FileName + "'><label class='title_warper'>" + data[i].FileName + "</label></div></li>";
                                    $("#ThumbnailList").append(li);

                                    //set ocrflag
                                    var imgclass = "detail_warper detail" + GetDocumnetType(data[i].FileExt);
                                    if (data[i].OCRFlag == 1) {
                                        imgclass += " ocrflag";
                                    }
                                    var imgelem = "<div class='" + imgclass + "'";
                                    imgelem += " nt='" + GetDocumnetType(data[i].FileExt) + "'";
                                    imgelem += " filePath='" + data[i].FilePath + "'";
                                    imgelem += " fileName='" + data[i].FileName + "'";
                                    imgelem += " autoid='" + data[i].AutoID + "'></div>";

                                    icount++;
                                    //bind details
                                    $("#TableList").jqGrid('addRowData', icount + 1,
            		                {
            		                    '图标': imgelem,
            		                    '文件名': data[i].FileName,
            		                    '扩展名': data[i].FileExt,
            		                    '扫描标记': (data[i].OCRFlag == 1) ? "已扫描" : "未扫描"
            		                });
                                }
                            }
                        }
                    },
                    function (err, textStatus) {
                        alert('操作失败');
                    },
                    this);
                },
                complete: function (data, textStatus) {
                    top.IndexScript.WaitWindow.Hide();
                }
            });
        }

        function GetDocumnetType(fileType) {
            var intFileType = 6;
            switch (fileType.toLocaleLowerCase()) {
                case "docx":
                    intFileType = 3;
                    break;
                case "doc":
                    intFileType = 3;
                    break;
                case "xls":
                    intFileType = 2;
                    break;
                case "xlsx":
                    intFileType = 2;
                    break;
                case "pdf":
                    intFileType = 4;
                    break;
                case "bmp":
                case "jpg":
                case "gif":
                case "png":
                case "tif":
                    intFileType = 5;
                    break;
                case "db":
                    //去掉Thumbs.db文件
                    intFileType = 7;
                    break;
                default:
                    intFileType = 6;
                    break;
            }
            return intFileType;
        }
    }

    this.IndexScript = {
        init:
        function () {
            if (!!_inited) return;

            $('.date-pick').datepicker({
                dateFormat: 'yy-mm-dd'
            });
            menuInit();
            //init project info
            InitProjectDialog();
            //init new project info
            InitNewProjectDialog();
            //init module info
            InitModuleDialog();
            //init sub module info
            InitSubModuleDialog();
            //init sub field info
            InitSubFieldDialog();
            //init new sub field info
            InitNewSubFieldDialog();
            //init company info
            InitCompanyInfoDialog();
            //InitUploadFilesDialog
            InitUploadFilesDialog();
            InitCreateFolderDialog();
            //init ocr dialog
            InitDocumentOcrDialog();
            //init document info
            InitDocumentInfoDialog();
            //init password info 
            InitPasswordInfoDialog();
            //init module import
            InitModuleImportDialog();
            //init alive timer
            setInterval(function () { getStaticInfo(); }, 300000);
            _inited = true;
        },
        getSystemParameter: function (param) {
            var p = top.window.__systemparameter || {};
            if (typeof param == "undefined")
                return p;
            return p[param];
        },
        ProjectDialog: {
            Open: function (info, cb) {
                ProjectDialogInfo = { info: info, cb: cb };
                var tbproject = $('#tbproject', '#ProjectDialog');
                if (info && info != null) {
                    tbproject.empty();
                    var isselect = false;
                    for (var i = 0; i < info.length; i++) {
                        var tr = "<tr autoid='" + info[i].AutoID + "'>";
                        tr += "<td>";
                        //项目是否选中
                        if (info[i].SelectFlag > 0) {
                            tr += "<input type='checkbox' class='cbproject' checked='true'/>";
                            isselect = true;
                        }
                        else {
                            tr += "<input type='checkbox' class='cbproject'/>";
                        }
                        tr += "</td>";
                        tr += "<td>";
                        tr += info[i].ProjectName;
                        tr += "</td>";
                        tr += "<td>";
                        tr += info[i].CreateTime;
                        tr += "</td>";
                        tr += "</tr>";
                        tbproject.append($(tr).data(info[i]));
                    }
                    if (isselect) {
                        $('#cbRememberMe').attr('checked', true);
                    }
                    else {
                        $('#cbRememberMe').removeAttr('checked');
                        var autoid = ProjectInfoMgr.getServerProjectInfo();
                        if (autoid > 0) {
                            tbproject.find('tr[autoid=' + autoid + ']').find('.cbproject').attr('checked', true);
                        }
                    }
                }

                //隐藏关闭按钮
                $('#ui-dialog-title-ProjectDialog').next().hide();
                $('#ProjectDialog').dialog("open");
            },
            Close: function () {
                $('#ProjectDialog').dialog("close");
            }
        },
        UploadFilesDialogControl: {
            Open: function (param, callback) {
                $('#UploadFilesDialog').data('data', param);
                $('#txtAttachmentsName').val('');
                $('#UploadFilesDialog').dialog("open");
                UploadControlDialogInfo = { cB: callback };
            },
            Close: function () {
                $('#UploadFilesDialog').dialog("close");
            }
        },
        CreateFolderDialogControl: {
            Open: function (param, callback) {
                $('#CreateFolderDialog').data('data', param);
                $('#txtFolderName').val('');
                $('#CreateFolderDialog').dialog("open");
                UploadControlDialogInfo = { cB: callback };
            },
            Close: function () {
                $('#CreateFolderDialog').dialog("close");
            }
        },
        NewProjectDialog: {
            Open: function (info, cb) {
                NewProjectDialogInfo = { info: info, cb: cb };
                if (info && info != null) {
                    $('#txtProjectName', '#NewProjectDialog').val(info.ProjectName);
                    $('#txtProjectDescription', '#NewProjectDialog').val(info.Description);
                    $('#txtProjectDisk', '#NewProjectDialog').val(info.ProjectDisk);
                }
                else {
                    $('#txtProjectName', '#NewProjectDialog').val('');
                    $('#txtProjectDescription', '#NewProjectDialog').val('');
                    $('#txtProjectDisk', '#NewProjectDialog').val('');
                }
                $('#NewProjectDialog').dialog("open");
            },
            Close: function () {
                $('#NewProjectDialog').dialog("close");
            }
        },
        ModuleDialog: {
            Open: function (info, cb) {
                ModuleDialogInfo = { info: info, cb: cb };
                if (info && info != null) {
                    $('#txtModuleName', '#ModuleDialog').val(info.ModuleName);
                    $('#txtModuleDescription', '#ModuleDialog').val(info.Description);
                }
                else {
                    $('#txtModuleName', '#ModuleDialog').val('');
                    $('#txtModuleDescription', '#ModuleDialog').val('');
                }
                $('#ModuleDialog').dialog("open");
            },
            Close: function () {
                $('#ModuleDialog').dialog("close");
            }
        },
        SubModuleDialog: {
            Open: function (info, cb) {
                SubModuleDialogInfo = { info: info, cb: cb };
                if (info && info != null) {
                    $('#txtSubModuleName', '#SubModuleDialog').val(info.ModuleSubName);
                    $('#txtSubModuleDescription', '#SubModuleDialog').val(info.Description);
                }
                else {
                    $('#txtSubModuleName', '#SubModuleDialog').val('');
                    $('#txtSubModuleDescription', '#SubModuleDialog').val('');
                }
                $('#SubModuleDialog').dialog("open");
            },
            Close: function () {
                $('#SubModuleDialog').dialog("close");
            }
        },
        SubFieldDialog: {
            Open: function (info, cb) {
                SubFieldDialogInfo = { info: info, cb: cb };
                SubFieldMgr.GetData(info);
                if (info.CreateFlag == 1) {
                    $('#spanSubFieldInfo').html('已初始化');
                    $('.btnSubFieldSetting').attr('disabled', 'disabled');
                    $('#btnSubFieldModify', '#SubFieldDialog').removeAttr('disabled');
                }
                else {
                    $('#spanSubFieldInfo').html('未初始化');
                    $('.btnSubFieldSetting').removeAttr('disabled');
                }
                $('#btnSubFieldModify', '#SubFieldDialog').data('info', info);
                $('#SubFieldDialog').dialog("open");
            },
            Close: function () {
                $('#SubFieldDialog').dialog("close");
                //刷新界面
                if (SubFieldDialogInfo && SubFieldDialogInfo.cb) {
                    SubFieldDialogInfo.cb();
                }
            }
        },
        NewSubFieldDialog: {
            Open: function (info, cb, flags) {
                NewSubFieldDialogInfo = { info: info, cb: cb };
                if (info && info != null) {
                    $('#txtFieldName', '#NewSubFieldDialog').val(info.FieldName);
                    $('#sltFieldType', '#NewSubFieldDialog').val(info.FieldType);
                    $('#sltFieldType', '#NewSubFieldDialog').trigger('change');
                    $('#txtFieldLen', '#NewSubFieldDialog').val(info.FieldLen);
                    if (info.QueryFlag == 1) {
                        $('#cbQueryFlag', '#NewSubFieldDialog').attr('checked', 'checked');
                    }
                    else {
                        $('#cbQueryFlag', '#NewSubFieldDialog').removeAttr('checked');
                    }
                    if (info.ResultFlag == 1) {
                        $('#cbResultFlag', '#NewSubFieldDialog').attr('checked', 'checked');
                    }
                    else {
                        $('#cbResultFlag', '#NewSubFieldDialog').removeAttr('checked');
                    }
                    $('#sltSpecialFlag', '#NewSubFieldDialog').val(info.SpecialFlag);
                    $('#txtIniValue', '#NewSubFieldDialog').val(info.IniValue);
                    if (info.BlankFlag == 2) {
                        $('#cbBlankFlag', '#NewSubFieldDialog').attr('checked', 'checked');
                    }
                    else {
                        $('#cbBlankFlag', '#NewSubFieldDialog').removeAttr('checked');
                    }
                }
                else {
                    $('#txtFieldName', '#NewSubFieldDialog').val('');
                    $('#sltFieldType', '#NewSubFieldDialog').val('C');
                    $('#sltFieldType', '#NewSubFieldDialog').trigger('change');
                    $('#txtFieldLen', '#NewSubFieldDialog').val('50');
                    $('#cbQueryFlag', '#NewSubFieldDialog').removeAttr('checked');
                    $('#cbResultFlag', '#NewSubFieldDialog').removeAttr('checked');
                    $('#sltSpecialFlag', '#NewSubFieldDialog').val('0');
                    $('#txtIniValue', '#NewSubFieldDialog').val('');
                    $('#cbBlankFlag', '#NewSubFieldDialog').removeAttr('checked');
                }

                //$('#sltFieldType', '#NewSubFieldDialog').trigger('change');

                //enable drop down
                $('#sltFieldType', '#NewSubFieldDialog').removeAttr('disabled');
                if (flags && flags != null) {
                    if (flags.CreateFlag == 1) {
                        $('#sltFieldType', '#NewSubFieldDialog').attr('disabled', 'disabled');
                        $('#txtFieldLen', '#NewSubFieldDialog').attr('disabled', 'disabled');
                    }
                }

                $('#NewSubFieldDialog').dialog("open");
            },
            Close: function () {
                $('#NewSubFieldDialog').dialog("close");
            }
        },
        CompanyInfoDialog: {
            Open: function (info, cb) {
                CompanyInfoDialogInfo = { info: info, cb: cb };
                CompanyDialogMgr.GetData();
                if (info && info != null) {
                    CompanyDialogMgr.SetInfo(info);
                }
                $('#CompanyInfoDialog').dialog("open");
            },
            Close: function () {
                $('#CompanyInfoDialog').dialog("close");
            }
        },
        ModuleInfoAddDialog: {
            Init: function (info, menuname) {
                //first to destory 
                top.IndexScript.ModuleInfoAddDialog.Destroy();
                //init ui
                $('#tbModuleInfoAdd').empty();
                //init ui events
                $('.Wdate', '#tbModuleInfoAdd').die().live('click', function () {
                    WdatePicker({ isShowClear: false, readOnly: true, dateFmt: 'yyyy-MM-dd' });
                });
                $('.wdQuery', '#tbModuleInfoAdd').die().live('click', function () {
                    var info = {};
                    var txtctr = $(this);
                    info.FilePath = txtctr.val();
                    info.FileData = txtctr.data('data');
                    var callback = function (params) {
                        if (params != null) {
                            txtctr.val(params.FilePath);
                            txtctr.data('data', params.FileData);
                        }
                    };
                    top.IndexScript.DocumentInfoDialog.Open(info, callback);
                });
                $('.wdbtnQuery', '#tbModuleInfoAdd').die().live('click', function () {
                    var info = {};
                    var txtctr = $(this).prev();
                    info.FilePath = txtctr.val();
                    info.FileData = txtctr.data('data');
                    var callback = function (params) {
                        if (params != null) {
                            txtctr.val(params.FilePath);
                            txtctr.data('data', params.FileData);
                        }
                    };
                    top.IndexScript.DocumentInfoDialog.Open(info, callback);
                });
                $('.csQuery', '#tbModuleInfoAdd').die().live('click', function () {
                    var txtctr = $(this);
                    var info = {};
                    info.CompanyName = txtctr.val();
                    var callback = function (params) {
                        txtctr.data('data', params);
                        if (params != null) {
                            txtctr.val(params.CompanyName);
                        }
                    };
                    top.IndexScript.CompanyInfoDialog.Open(info, callback);
                });
                $('.csbtnQuery', '#tbModuleInfoAdd').die().live('click', function () {
                    var txtctr = $(this).prev();
                    var info = {};
                    info.CompanyName = txtctr.val();
                    var callback = function (params) {
                        txtctr.data('data', params);
                        if (params != null) {
                            txtctr.val(params.CompanyName);
                        }
                    };
                    top.IndexScript.CompanyInfoDialog.Open(info, callback);
                });
                //init ui
                if (info && info != null) {
                    for (var i = 0; i < info.length; i++) {
                        var d = info[i];
                        if (d.DeleteFlag > 1) {
                            var tr = $('<tr>').data('data', d);
                            var td = $('<td>').html(d.FieldName);
                            var ctd = $('<td>');
                            var str = '';
                            if (d.SpecialFlag > 0) {
                                switch (d.SpecialFlag) {
                                    case 1:
                                        {
                                            //文档路径
                                            str += '<input type="text" class="wdQuery valueQuery" readonly="readonly" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '" ';
                                            str += 'value="' + d.IniValue + '" ';
                                            str += '/>';
                                            str += '<input type="button" class="wdbtnQuery" value="..." />';
                                        }
                                        break;
                                    case 2:
                                        {
                                            //厂商信息
                                            str += '<input type="text" class="csQuery valueQuery" readonly="readonly" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '" ';
                                            str += 'value="' + d.IniValue + '" ';
                                            str += '/>';
                                            str += '<input type="button" class="csbtnQuery" value="..." />';
                                        }
                                        break;
                                    case 3:
                                        {
                                            //所属专业
                                            var zyinfo = top.IndexScript.getSystemParameter('ProfessionalInfo');
                                            var str = '<select class="zyQuery valueQuery" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '">';
                                            str += '<option></option>';
                                            if (zyinfo != null) {
                                                for (var n = 0; n < zyinfo.length; n++) {
                                                    if (d.IniValue == zyinfo[n].GeneralValue1) {
                                                        str += '<option selected="selected">';
                                                    }
                                                    else {
                                                        str += '<option>';
                                                    }
                                                    str += zyinfo[n].GeneralValue1;
                                                    str += '</option>';
                                                }
                                            }
                                            str += '</select>';
                                        }
                                        break;
                                    case 4:
                                        {
                                            //文件类型
                                            var wjinfo = top.IndexScript.getSystemParameter('FileType');
                                            var str = '<select class="wjQuery valueQuery" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '">';
                                            str += '<option></option>';
                                            if (wjinfo != null) {
                                                for (var n = 0; n < wjinfo.length; n++) {
                                                    if (d.IniValue == wjinfo[n].GeneralValue1) {
                                                        str += '<option selected="selected">';
                                                    }
                                                    else {
                                                        str += '<option>';
                                                    }
                                                    str += wjinfo[n].GeneralValue1;
                                                    str += '</option>';
                                                }
                                            }
                                            str += '</select>';
                                        }
                                        break;
                                    default:
                                        {
                                            str += '<input type="text" class="cQuery valueQuery" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '" ';
                                            str += 'value="' + d.IniValue + '" ';
                                            str += '/>';
                                        }
                                        break;
                                }
                            }
                            else {
                                switch (d.FieldType) {
                                    case 'I':
                                        {
                                            str += '<input type="text" class="iQuery valueQuery" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '" ';
                                            str += 'onkeyup="if(isNaN(value))execCommand(\'undo\')" ';
                                            str += 'onafterpaste="if(isNaN(value))execCommand(\'undo\')" ';
                                            str += 'value="' + d.IniValue + '" ';
                                            str += '/>';
                                        }
                                        break;
                                    case 'D':
                                        {
                                            str += '<input type="text" class="Wdate dQuery valueQuery" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'value="' + d.IniValue + '" ';
                                            str += '/>';
                                        }
                                        break;
                                    case 'B':
                                        {
                                            str += '<select class="bQuery valueQuery" FieldType="' + d.FieldType + '">';
                                            str += '<option value="1" selected="selected">是</option>';
                                            str += '<option value="2">否</option>';
                                            str += '</select>';
                                        }
                                        break;
                                    default:
                                        {
                                            str += '<input type="text" class="cQuery valueQuery" ';
                                            str += 'FieldType="' + d.FieldType + '" ';
                                            str += 'maxlength="' + d.FieldLen + '" ';
                                            str += 'value="' + d.IniValue + '" ';
                                            str += '/>';
                                        }
                                        break;
                                }
                            }
                            ctd.append(str);
                            tr.append(td);
                            tr.append(ctd);
                            if (d.ResultFlag == 1) {
                                tr.css('display', 'block');
                            }
                            else {
                                tr.css('display', 'none');
                            }
                            $('#tbModuleInfoAdd').append(tr);
                        }
                    }
                }
                $('#tbModuleInfoAdd').data('data', info);
                ModuleInfoAddDialogInfo = {};
                $('#ModuleInfoAddDialog').dialog({
                    autoOpen: false,
                    title: ((menuname && menuname != null) ? menuname : ''),
                    width: 400,
                    height: 300,
                    modal: true
                });

                $('#btnModuleInfoConfirm', '#ModuleInfoAddDialog').die().live('click', function () {
                    var result = true;
                    var trresult = '';
                    var trlist = $('#tbModuleInfoAdd').find('>tr');
                    if (trlist && trlist != null) {
                        $(trlist).each(function () {
                            var trnode = $(this);
                            var trdata = trnode.data('data');
                            if (trdata && trdata != null) {
                                var trvalue = trnode.find(".valueQuery");
                                //必填项
                                if (trvalue && trvalue != null) {
                                    var v = $.trim($(trvalue).val());
                                    if (v == '' && trdata.BlankFlag == 2 && trdata.ResultFlag == 1) {
                                        alert('请输入' + trdata.FieldName);
                                        result = false;
                                        return false;
                                    }
                                    trresult += trdata.FieldType;
                                    trresult += trdata.AutoID;
                                    trresult += ',';
                                    trresult += v;
                                    trresult += ';';
                                }
                            }
                        });
                    }
                    if (result) {
                        if (ModuleInfoAddDialogInfo && ModuleInfoAddDialogInfo.cb) {
                            ModuleInfoAddDialogInfo.cb(trresult);
                        }
                        top.IndexScript.ModuleInfoAddDialog.Close();
                    }
                });
                $('#btnModuleInfoCancel', '#ModuleInfoAddDialog').die().live('click', function () {
                    top.IndexScript.ModuleInfoAddDialog.Close();
                });
            },
            Open: function (info, cb, type) {
                ModuleInfoAddDialogInfo = { info: info, cb: cb };

                //first to empty textbox
                $('#tbModuleInfoAdd').find('.valueQuery').val('');

                if (info != null) {
                    switch (type) {
                        case 'Select':
                            {
                                //init values
                                $('.csbtnQuery', '#ModuleInfoAddDialog').attr('disabled', 'disabled');
                                $('.wdbtnQuery', '#ModuleInfoAddDialog').attr('disabled', 'disabled');
                                $('.valueQuery', '#ModuleInfoAddDialog').val('').attr('disabled', 'disabled');
                            }
                            break;
                        case "Edit":
                            {
                                //Edit
                                $('.csbtnQuery', '#ModuleInfoAddDialog').removeAttr('disabled');
                                $('.wdbtnQuery', '#ModuleInfoAddDialog').removeAttr('disabled');
                                $('.valueQuery', '#ModuleInfoAddDialog').removeAttr('disabled');
                            }
                            break;
                        default:
                            break;
                    }
                    if (info.KeyValue && info.KeyValue != null) {
                        var trlist = $('#tbModuleInfoAdd').find('>tr');
                        if (trlist && trlist != null) {
                            $(trlist).each(function () {
                                var trnode = $(this);
                                var trdata = trnode.data('data');
                                if (trdata && trdata != null) {
                                    var values = info.KeyValue[trdata.FieldName];
                                    if (trdata.FieldType == 'D') {
                                        values = values.substr(0, 10);
                                    }
                                    trnode.find('.valueQuery').val(values);
                                }
                            });
                        }
                    }
                }
                else {
                    //insert
                    $('.csbtnQuery', '#ModuleInfoAddDialog').removeAttr('disabled');
                    $('.wdbtnQuery', '#ModuleInfoAddDialog').removeAttr('disabled');
                    $('.valueQuery', '#ModuleInfoAddDialog').removeAttr('disabled');
                }
                $('#ModuleInfoAddDialog').dialog("open");
            },
            Close: function () {
                $('#ModuleInfoAddDialog').dialog("close");
            },
            Destroy: function () {
                $('#ModuleInfoAddDialog').dialog("destroy");
            }
        },
        DocumentOcrDialog: {
            Open: function (info, cb) {
                DocumentOcrDialogInfo = { info: info, cb: cb };
                $('#DocumentOcrDialog').dialog("open");
            },
            Close: function () {
                $('#DocumentOcrDialog').dialog("close");
            }
        },
        DocumentInfoDialog: {
            Open: function (info, cb) {
                DocumentInfoDialogInfo = { info: info, cb: cb };
                if (info && info != null) {
                    $('#txtDocumentInfoPath').val(info.FilePath);
                    $('#txtDocumentInfoPath').data('data', info.FileData);
                }
                else {
                    $('#txtDocumentInfoPath').val('');
                    $('#txtDocumentInfoPath').data('data', null);
                }
                $('#DocumentInfoDialog').dialog("open");
                $(window).trigger('resize');
            },
            Close: function () {
                $('#DocumentInfoDialog').dialog("close");
            }
        },
        PasswordInfoDialog: {
            Open: function (info, cb) {
                PasswordInfoDialogInfo = { info: info, cb: cb };
                var param = top.IndexScript.getSystemParameter('UserInfo');
                if (param && param != null && param.length > 0) {
                    $('#txtUserName').val(param[0].UserName);
                }
                else {
                    $('#txtUserName').val('');
                }
                $('#txtOldPassword').val('');
                $('#txtPassword').val('');
                $('#txtPasswordConfirm').val('');
                $('#PasswordInfoDialog').dialog("open");
            },
            Close: function () {
                $('#PasswordInfoDialog').dialog("close");
            }
        },
        ModuleImportDialog: {
            Open: function (info, cb) {
                if (info == null) {
                    info = ProjectInfoMgr.getProjectInfo();
                }
                //当前项目ID
                var autoid = ProjectInfoMgr.getServerProjectInfo();
                ModuleImportDialogInfo = { info: info, cb: cb };
                var tbproject = $('#tbprojectimport', '#ModuleImportDialog');
                if (info && info != null) {
                    tbproject.empty();
                    var isselect = false;
                    for (var i = 0; i < info.length; i++) {
                        //屏蔽掉当前项目
                        if (info[i].AutoID != autoid) {
                            var tr = "<tr autoid='" + info[i].AutoID + "'>";
                            tr += "<td>";
                            tr += "<input type='checkbox' class='cbproject'/>";
                            tr += "</td>";
                            tr += "<td>";
                            tr += info[i].ProjectName;
                            tr += "</td>";
                            tr += "<td>";
                            tr += info[i].CreateTime;
                            tr += "</td>";
                            tr += "</tr>";
                            tbproject.append($(tr).data(info[i]));
                        }
                    }
                }
                $('#ModuleImportDialog').dialog("open");
            },
            Close: function () {
                $('#ModuleImportDialog').dialog("close");
            }
        },
        WaitWindow: {
            Show: function () {
                ShowWaitWindow();
            },
            Hide: function () {
                HideWaitWindow();
            }
        }
    }
})()
$(function () {
    IndexScript.init();
})